const {merge} = require("webpack-merge");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCssAssetsWebpackPlugin = require("optimize-css-assets-webpack-plugin");
const commonConfig = require("./webpack.common.js");

const prodConfig = {
  mode: 'production',
  devtool: "none",
  output: {
    path: __dirname + "/dist",
  },
  module: {
      rules: [
        {
            test: /\.less$/,
            use: [
              MiniCssExtractPlugin.loader,
              "css-loader", // translates CSS into CommonJS
              "less-loader", // compiles Less to CSS
            ],
          },
          {
            test: /\.css$/,
            use: [
              MiniCssExtractPlugin.loader, 
              "css-loader", 
              "postcss-loader"
            ],
          },
      ]
  },
  plugins: [
    new CleanWebpackPlugin(),
    new CopyWebpackPlugin({
      patterns: [{ from: "public" }],
    }),
    new MiniCssExtractPlugin(),
    new OptimizeCssAssetsWebpackPlugin(),
  ],
};

module.exports = merge(commonConfig, prodConfig);
